package com.livecooking;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Switch;
import android.widget.TextView;

class ListAdapter extends ArrayAdapter<String> {

	public Context myContext;
	public String[] foodNameList;
	public List<Integer> foodIdList;
	public GetImages getIma;

	public ListAdapter(Context context, String[] foodNameList,
			List<Integer> foodIdList) {
		super(context, R.layout.listitem, foodNameList);
		this.myContext = context;
		this.foodNameList = foodNameList;
		this.foodIdList = foodIdList;
		
	}

	public View getView(int position, View convertView, ViewGroup parent) {

		View rowView = convertView;
		ViewHolder viewHolder = null;
//		List<Integer> imageList = getAllImage(foodIdList);

		if (rowView == null) {
			LayoutInflater inflater = (LayoutInflater) myContext
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			rowView = inflater.inflate(R.layout.listitem, null);

			viewHolder = new ViewHolder();
			viewHolder.text = (TextView) rowView.findViewById(R.id.txtName);
			viewHolder.image = (ImageView) rowView.findViewById(R.id.imvFood);
			viewHolder.linear= (LinearLayout) rowView.findViewById(R.id.item);
			
			rowView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		viewHolder.text.setText(foodNameList[position]);
		viewHolder.image.setImageResource(getIma.getImage(foodIdList.get(position)));
//		viewHolder.image.setImageResource(imageList.get(position));
		if(position%2==0){
			viewHolder.linear.setBackgroundColor(Color.parseColor("#ffffff"));
		}
		else{
			viewHolder.linear.setBackgroundColor(Color.parseColor("#eeeeee"));
		}
		return rowView;
	}

	@Override
	public int getCount() {
		return foodNameList.length;
	}

	static class ViewHolder {

		public LinearLayout linear;
		public TextView text;
		public ImageView image;
	}

}
